package com.casic.ops.entity.vo;

import com.casic.ops.entity.dto.ApplicationPipelineTaskStatisticsDTO;
import com.casic.ops.utils.Utils;
import com.orion.utils.convert.TypeStore;
import lombok.Data;

/**
 * @ClassName ops-platform
 * @Description 流水线执行统计指标
 * @Author mianbin
 * @Date 2022/5/31 10:59
 * @Version 1.0
 **/
@Data
public class ApplicationPipelineTaskStatisticsMetricsVO {

    /**
     * 执行次数
     */
    private Integer execCount;

    /**
     * 成功次数
     */
    private Integer successCount;

    /**
     * 失败次数
     */
    private Integer failureCount;

    /**
     * 平均发布时长ms (成功)
     */
    private Long avgUsed;

    /**
     * 平均发布时长 (成功)
     */
    private String avgUsedInterval;

    public static ApplicationPipelineTaskStatisticsMetricsVO pipelineTaskStatisticsDTO2pipelineTaskStatisticsMetricsVO(ApplicationPipelineTaskStatisticsDTO p) {
        ApplicationPipelineTaskStatisticsMetricsVO vo = new ApplicationPipelineTaskStatisticsMetricsVO();
        vo.setExecCount(p.getExecCount());
        vo.setSuccessCount(p.getSuccessCount());
        vo.setFailureCount(p.getFailureCount());
        vo.setAvgUsed(p.getAvgUsed());
        vo.setAvgUsedInterval(Utils.interval(p.getAvgUsed()));
        return vo;
    }

    static {
        TypeStore.STORE.register(ApplicationPipelineTaskStatisticsDTO.class, ApplicationPipelineTaskStatisticsMetricsVO.class, p -> {
            ApplicationPipelineTaskStatisticsMetricsVO vo = new ApplicationPipelineTaskStatisticsMetricsVO();
            vo.setExecCount(p.getExecCount());
            vo.setSuccessCount(p.getSuccessCount());
            vo.setFailureCount(p.getFailureCount());
            vo.setAvgUsed(p.getAvgUsed());
            vo.setAvgUsedInterval(Utils.interval(p.getAvgUsed()));
            return vo;
        });
    }
}
